import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:module/register.dart';

import 'const.dart';
import 'login.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage>
    with SingleTickerProviderStateMixin {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    tabController = TabController(length: 2, vsync: this);
    tabController.animateTo(1);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // resizeToAvoidBottomInset: false,
      appBar: AppBar(
        backgroundColor: Constants.bgColor,
        elevation: 0,
        bottom: PreferredSize(
          preferredSize: Size(MediaQuery.of(context).size.width, 44),
          child: Material(
            child: Container(
              color: Constants.bgColor,
              width: 120.0,
              child: TabBar(
                controller: tabController,
                labelColor: Colors.black,
                indicatorPadding: EdgeInsets.zero,
                indicator: UnderlineTabIndicator(
                  borderSide: BorderSide(width: 2.0, color: Colors.blue),
                ),
                // indicator: BoxDecoration(),
                tabs: [
                  Align(
                    alignment: Alignment.bottomRight,
                    child: Tab(
                      text: '注册',
                    ),
                  ),
                  Align(
                    alignment: Alignment.bottomLeft,
                    child: Tab(
                      text: '登录',
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
      body: Container(
        color: Constants.bgColor,
        padding: EdgeInsets.symmetric(
            horizontal: mScreenWidth * 0.1, vertical: mScreenHeight * 0.02),
        child: TabBarView(
          controller: tabController,
          children: [
            Register(),
            Login(),
          ],
        ),
      ),
    );
  }
}
